package logic

import (
	"context"
	"week3/projectsrv/projectsrv"

	"week3/client/internal/svc"
	"week3/client/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SearchGoodsByPriceLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSearchGoodsByPriceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchGoodsByPriceLogic {
	return &SearchGoodsByPriceLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SearchGoodsByPriceLogic) SearchGoodsByPrice(req *types.SearchGoodsByPriceReq) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.Rpc.SearchGoodsByPrice(l.ctx, &projectsrv.SearchGoodsByPriceReq{SortId: int32(req.SortId)})
	if err != nil {
		return nil, err
	}
	resp = &types.Response{
		Data: map[string]interface{}{
			"data": res.Goods,
		},
	}
	return resp, nil
}
